import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-09-19
 * Time: 11:20
 */
public class StringDemo1 {

    public static void main11(String[] args) {
        //字符转数字
        char c = 'a';
        int num = c - 0;
        System.out.println(num);
        //数字转字符
        int num1 = 98;
        char c1 = (char)num1;
        System.out.println(c1);
    }
    public static void main10(String[] args) {
        // 数字转字符串
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println("=================================");
        // 字符串转数字
        // 注意：Integer、Double等是Java中的包装类型
        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1);
        System.out.println(data2);
    }
    public static void main9(String[] args) {
        //1.获取手机号码
        String phoneNumber = "13145689468";

        //2.截取手机号码前三位
        String start = phoneNumber.substring(0,3);

        //3.截取手机号码后四位
        String end = phoneNumber.substring(7);

        //4.拼接
        String result = start + "****" + end;

        //5.打印
        System.out.println(result);
    }
    public static void main8(String[] args) {
        //1.键盘录入一个金额
        Scanner scanner = new Scanner(System.in);
        int money = 0;
        while(true){
            System.out.println("请输入一个金额");
            money = scanner.nextInt();
            if(money >= 0 && money <= 9999999){
                break;
            }else {
                System.out.println("金额无效");
            }
        }
        //2.将数字变成大写；得到money的每一位
        //定义变量表示钱的大写
        String moneyStr = "";
        while (true){//1235
            //从个位开始获得
            int ge = money % 10;
            String captialNumber = getCaptialNumber(ge);
            //把转换之后的大写拼接到moneyStr中
            //moneyStr = moneyStr + captialNumber;
            //第一次循环：""+"伍" = "伍"
            //第二次循环："伍"+"叁" = "伍叁"
            moneyStr = captialNumber + moneyStr;
            //第一次循环："伍"+"" = "伍"
            //第二次循环："叁"+"伍" = "叁伍"
            money = money / 10;
            if(money == 0){
                break;
            }
        }

        //3.在前面补0，补齐7位
        int count = 7 - moneyStr.length();
        for (int i = 0; i < count; i++) {
            moneyStr = "零" + moneyStr;
        }

        //4.插入单位
        //定义数组表示单位
        String[] arr = {"佰","拾","万","仟","佰","拾","元"};

        //遍历字符串
        String result = "";
        for (int i = 0; i < moneyStr.length(); i++) {
            char c = moneyStr.charAt(i);
            //把大写数组和单位拼接
        }
        System.out.println();
    }
    public static String getCaptialNumber(int number){
        //定义数组，让数字和大写中文产生一个对应关系
        String[] arr = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
        //返回结果
        return arr[number];
    }
    public static void main7(String[] args) {
        //定义一个方法，实现字符串反转。键盘录入一个字符串，调用该方法后，在控制台输出结果
        //
        //例如，键盘录入 abc，输出结果 cba
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str1 = scanner.next();

        System.out.println(reverse(str1));

    }
    public static String reverse(String str){
        String result = "";
        for (int i = str.length() - 1; i >= 0 ; i--) {
            char c = str.charAt(i);
            result += c;
        }
        return result;
    }
    public static void main6(String[] args) {
        //键盘录入一个字符串，统计该字符串中大写字母字符，小写字母字符，数字字符出现的次数(不考虑其他字符)
        //1.键盘录入字符串
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str = scanner.next();

        //2.统计
        int bigCount = 0;
        int smallCount = 0;
        int numberCount = 0;
        //遍历字符串
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if(c >= 'a' && c <= 'z'){
                smallCount++;
            } else if (c >= 'A' && c <= 'Z') {
                bigCount++;
            }else if(c >= '0' && c <= '9'){
                numberCount++;
            }
        }

        //3.输出打印
        System.out.println("大写字母有：" + bigCount +"个");
        System.out.println("小写字母有：" + smallCount +"个");
        System.out.println("数字字母有：" + numberCount +"个");

    }
    public static void main5(String[] args) {
        String rightUsername = "张三";
        String rightPassword = "123456";


        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            //键盘输入
            System.out.println("请输入用户名：");
            String username = scanner.next();
            System.out.println("请输入密码：");
            String password = scanner.next();

            //进行字符串比较
            if(username.equals(rightUsername) && password.equals(rightPassword)){
                System.out.println("用户登录成功");
                break;
            }else {
                System.out.println("用户登录失败，用户名或密码有误，还剩下" + (2-i) +"次机会");
            }
        }

    }
    public static void main4(String[] args) {
        //1、假设键盘录入一个abc
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str1 = scanner.next(); //键盘录入返回的结果是new出来的
        //2、代码中定义一个字符串abc
        String str2 = "abc";
        //3、用==进行比较
        System.out.println(str1 == str2);
    }
    public static void main3(String[] args) {
        String s1 = "hello";
        String s2 = "world";
        //比较字符串对象中的内容是否完全相同
        boolean result = s1.equals(s2);
        System.out.println(result);//false

        //比较字符串对象中的内容是否相同,忽略大小写
        String s3 = "Hello";
        boolean result2 = s1.equalsIgnoreCase(s3);
        System.out.println(result2);//true
    }
    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;
        System.out.println(s1);//hello
        System.out.println(s2);//world
        System.out.println(s3);//hello
    }
    public static void main1(String[] args) {

        //String s =   “abc”;直接赋值的方式创建字符串对象，内容就是abc
        String s = "abc";
        System.out.println(s);

        //public String()：创建一个空白字符串对象，不含有任何内容
        String s1 = new String();
        System.out.println("s1:" + s1 + "@");

        //public String(char[] chs)：根据字符数组的内容，来创建字符串对象
        char[] chs = {'a', 'b', 'c'};
        String s2 = new String(chs);
        System.out.println("s2:" + s2);

        //public String(byte[] bys)：根据字节数组的内容，来创建字符串对象
        byte[] bys = {97, 98, 99};
        String s3 = new String(bys);
        System.out.println("s3:" + s3);

        //String s = “abc”;	直接赋值的方式创建字符串对象，内容就是abc
        String s4 = "abc";
        System.out.println("s4:" + s4);

        //使用new String方式创建一个新的字符串对象
        String s5 = new String("abc");
        System.out.println(s5);
    }
}